import { defineStore } from 'pinia'
import { GoodsInfo } from '@/types/goods'
import { ApiRes } from '@/types/data'
import request from '@/utils/request'

export default defineStore('goods', {
  state() {
    return {
      info: {} as GoodsInfo, // 商品详情信息
    }
  },

  actions: {
    // 根据商品id 获取商品信息 存入info
    async getGoodsInfo(id: string) {
      const res = await request.get<ApiRes<GoodsInfo>>('/goods', {
        params: {
          id,
        },
      })
      this.info = res.data.result
    },

    resetInfo() {
      this.info = {} as GoodsInfo
    },
  },
})
